#!/sbin/runscript
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/quagga/files/zebra.init.2,v 1.2 2010/10/12 11:42:55 flameeyes Exp $

depend() {
    need net
    # this could be config file-dependent on OpenRC, but for now it
    # will do.
    use logger
}

start() {
    if [ ! -e /etc/quagga/${SVCNAME}.conf ] ; then
        eerror "Before starting ${SVCNAME} you have to configure it, by creating"
        eerror "a /etc/quagga/${SVCNAME}.conf file."
        eerror ""
        eerror "A sample file has been installed in `ls /usr/share/doc/quagga-*/samples/${SVCNAME}.conf.sample`"
        return 1
    fi

    if [ ! -d /var/run/quagga ] ; then
        mkdir -p /var/run/quagga
        chown quagga:quagga /var/run/quagga
        chmod 0750 /var/run/quagga
    fi

    ebegin "Cleaning up stale zebra routes..."
    ip route flush proto zebra
    eend $?

    ebegin "Starting ${SVCNAME}"
    start-stop-daemon \
        --start --exec /usr/sbin/${SVCNAME} \
        --pidfile /var/run/quagga/${SVCNAME}.pid \
	-- -d -f /etc/quagga/${SVCNAME}.conf ${EXTRA_OPTS} \
	--pid_file /var/run/quagga/${SVCNAME}.pid

    eend $?
}

stop() {
    ebegin "Stopping ${SVCNAME}"
    start-stop-daemon --stop \
        --pidfile /var/run/quagga/${SVCNAME}.pid
    eend $?
}
